package com.mchsdk.paysdk.bean;


import android.os.Handler;
import android.os.Message;
import android.text.TextUtils;

import com.mchsdk.open.ChangeRoleNameCallback;
import com.mchsdk.paysdk.common.Constant;
import com.mchsdk.paysdk.http.process.ChangeRoleNameProcess;
import com.mchsdk.paysdk.utils.MCLog;

public class ChangeRoleName {

    public static final String TAG = "ChangeRoleName";
    String type;
    String role_name;
    ChangeRoleNameCallback rnc;


    private Handler mHandler = new Handler() {

        @Override
        public void handleMessage(Message msg) {
            super.handleMessage(msg);
            switch (msg.what) {
                case Constant.Change_Role_Name_SUCCESS:// 修改成功
                    if (getRnc() != null) {
                        getRnc().callback("1");
                    }
                    break;
                case Constant.Change_Role_Name_FAIL:// 修改失败
                    if (getRnc() != null) {
                        getRnc().callback("0");
                    }
                    break;
            }
        }
    };

    public ChangeRoleName(String type, String role_name, ChangeRoleNameCallback rnc) {
        if (type != null) {
            this.type = type;
        } else {
            MCLog.w(TAG, "#type is null");
        }

        this.role_name = role_name;
        this.rnc = rnc;

    }

    /**
     * 配置更改用户名称需要的参数,发起请求
     */
    public void change() {
        if (null == PersonalCenterModel.getInstance().channelAndGame
                || TextUtils
                .isEmpty(PersonalCenterModel.getInstance().channelAndGame
                        .getAccount())) {
            MCLog.w(TAG,"请登录");
            return;
        }
        MCLog.w(TAG, "#type" + type);
        ChangeRoleNameProcess process = new ChangeRoleNameProcess();
        process.setRole_name(role_name);
        process.setType(1);
        process.post(mHandler);

    }

    public ChangeRoleNameCallback getRnc() {
        if (rnc != null) {
            return rnc;
        }
        return null;
    }
}
